package com.konke.sdslibrary.factroy;


import androidx.annotation.Nullable;
import android.text.TextUtils;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.konke.sdslibrary.SmartHomeApi;
import com.konke.sdslibrary.util.AsynTool;
import com.sds.sdk.android.sh.SH;
import com.sds.sdk.android.sh.SHCCURepository;
import com.sds.sdk.android.sh.SHDeviceRepository;
import com.sds.sdk.android.sh.SHLocationRepository;
import com.sds.sdk.android.sh.SHVirtualDeviceRepository;
import com.sds.sdk.android.sh.common.FloorId;
import com.sds.sdk.android.sh.common.SHClientState;
import com.sds.sdk.android.sh.common.SHDeviceRealType;
import com.sds.sdk.android.sh.common.SHDeviceSubType;
import com.sds.sdk.android.sh.common.SHDeviceType;
import com.sds.sdk.android.sh.common.SHGuardSensorType;
import com.sds.sdk.android.sh.common.util.JsonUtils;
import com.sds.sdk.android.sh.common.util.StringUtils;
import com.sds.sdk.android.sh.internal.request.ChopinFreshAirConfigArgsResult;
import com.sds.sdk.android.sh.internal.request.FancoilConfigArgsResult;
import com.sds.sdk.android.sh.internal.request.FloorheatingConfigArgResult;
import com.sds.sdk.android.sh.internal.request.GetFreshAirStatusResult;
import com.sds.sdk.android.sh.model.Action;
import com.sds.sdk.android.sh.model.AddCodeLibResult;
import com.sds.sdk.android.sh.model.AddCodedLockUserResult;
import com.sds.sdk.android.sh.model.AddIftttResult;
import com.sds.sdk.android.sh.model.AddRoomResult;
import com.sds.sdk.android.sh.model.AddSceneResult;
import com.sds.sdk.android.sh.model.AirBoxNodeArgResult;
import com.sds.sdk.android.sh.model.ArmingState;
import com.sds.sdk.android.sh.model.CodeLibBaseResult;
import com.sds.sdk.android.sh.model.CodeLibBindResult;
import com.sds.sdk.android.sh.model.CodeLibTaskResult;
import com.sds.sdk.android.sh.model.Condition;
import com.sds.sdk.android.sh.model.Controller;
import com.sds.sdk.android.sh.model.Device;
import com.sds.sdk.android.sh.model.DeviceOnlineState;
import com.sds.sdk.android.sh.model.DooyaReverseResult;
import com.sds.sdk.android.sh.model.FancoilSmartModel;
import com.sds.sdk.android.sh.model.FloorheatingArgsResult;
import com.sds.sdk.android.sh.model.Gateway;
import com.sds.sdk.android.sh.model.GetAirBoxDayStatisitcResult;
import com.sds.sdk.android.sh.model.GetAirBoxStateResult;
import com.sds.sdk.android.sh.model.GetAirSwitchStatusResult;
import com.sds.sdk.android.sh.model.GetAlarmRecordResult;
import com.sds.sdk.android.sh.model.GetCcuInfoResult;
import com.sds.sdk.android.sh.model.GetCcuVersionResult;
import com.sds.sdk.android.sh.model.GetCodedLockUserInfoResult;
import com.sds.sdk.android.sh.model.GetCodelibButtonsResult;
import com.sds.sdk.android.sh.model.GetCodelibResult;
import com.sds.sdk.android.sh.model.GetDayPowerResult;
import com.sds.sdk.android.sh.model.GetDevAppArgsResult;
import com.sds.sdk.android.sh.model.GetDevDetectedPowerResult;
import com.sds.sdk.android.sh.model.GetDevHwInfoResult;
import com.sds.sdk.android.sh.model.GetDevInfoResult;
import com.sds.sdk.android.sh.model.GetDevPowerResult;
import com.sds.sdk.android.sh.model.GetDevStatusLogResult;
import com.sds.sdk.android.sh.model.GetDimmableLightConfigResult;
import com.sds.sdk.android.sh.model.GetElectricalClearingDateResult;
import com.sds.sdk.android.sh.model.GetElectricalClearingInfoResult;
import com.sds.sdk.android.sh.model.GetElectricalEnergyArgsResult;
import com.sds.sdk.android.sh.model.GetElectricalEnergyValueResult;
import com.sds.sdk.android.sh.model.GetElectricalSwitchStatusResult;
import com.sds.sdk.android.sh.model.GetFancoilSmartModelResult;
import com.sds.sdk.android.sh.model.GetFancoilSystemStatusResult;
import com.sds.sdk.android.sh.model.GetFloorheatingStatusResult;
import com.sds.sdk.android.sh.model.GetFreshAirValueResult;
import com.sds.sdk.android.sh.model.GetGwWhitelistResult;
import com.sds.sdk.android.sh.model.GetGwWorkmodeResult;
import com.sds.sdk.android.sh.model.GetHomebridgeStatusResult;
import com.sds.sdk.android.sh.model.GetInfraredLastSendCodeResult;
import com.sds.sdk.android.sh.model.GetLeaveHomeDelayResult;
import com.sds.sdk.android.sh.model.GetLocalCodelibsResult;
import com.sds.sdk.android.sh.model.GetLockOpenRecordResult;
import com.sds.sdk.android.sh.model.GetLockUserListResult;
import com.sds.sdk.android.sh.model.GetMonthPowerResult;
import com.sds.sdk.android.sh.model.GetMusicControllerStatusResult;
import com.sds.sdk.android.sh.model.GetMusicListResult;
import com.sds.sdk.android.sh.model.GetSocketRunArgsResult;
import com.sds.sdk.android.sh.model.GetYearPowerResult;
import com.sds.sdk.android.sh.model.GetYouzhuanMusicListResult;
import com.sds.sdk.android.sh.model.GetZbDevOnlineSwitchResult;
import com.sds.sdk.android.sh.model.GetZigbeeDevPingResult;
import com.sds.sdk.android.sh.model.Group;
import com.sds.sdk.android.sh.model.HueLightStatus;
import com.sds.sdk.android.sh.model.IFTTT;
import com.sds.sdk.android.sh.model.IFTTTEX;
import com.sds.sdk.android.sh.model.KonkeLightStatus;
import com.sds.sdk.android.sh.model.Limit;
import com.sds.sdk.android.sh.model.MotorOpt;
import com.sds.sdk.android.sh.model.PrepareTestCodeLibResult;
import com.sds.sdk.android.sh.model.Room;
import com.sds.sdk.android.sh.model.Scene;
import com.sds.sdk.android.sh.model.ShortcutPanelConfig;
import com.sds.sdk.android.sh.model.TextIndicatorResult;
import com.sds.sdk.android.sh.model.VoidResult;
import com.sds.sdk.android.sh.model.WhiteDev;
import com.sds.sdk.android.sh.model.ZigbeeBoolSensorStatus;
import com.sds.sdk.android.sh.model.ZigbeeDeviceStatus;
import com.sds.sdk.android.sh.model.ZigbeeDimmerStatus;
import com.sds.sdk.android.sh.model.ZigbeeDooYaStatus;
import com.sds.sdk.android.sh.model.ZigbeeDoorContactStatus;
import com.sds.sdk.android.sh.model.ZigbeeExtensionSocketStatus;
import com.sds.sdk.android.sh.model.ZigbeeFanCoilStatus;
import com.sds.sdk.android.sh.model.ZigbeeFloorHeatingStatus;
import com.sds.sdk.android.sh.model.ZigbeeFreshAirStatus;
import com.sds.sdk.android.sh.model.ZigbeeMotorStatus;
import com.sds.sdk.android.sh.model.ZigbeeNumSensorStatus;
import com.sds.sdk.android.sh.model.ZigbeeSwitchStatus;
import com.sds.sdk.android.sh.model.ZigbeeUniversalBoosSensorStatus;
import com.zsj.comminlibrary.util.log.XLog;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

import io.netty.util.concurrent.Future;

/**
 * Created by L on 2016/6/16.
 */
class SmartHomeManager implements SmartHomeApi {

    private SH mSmartclient;
    private SHDeviceRepository mDevicerepository;
    private SHLocationRepository mLocationrepository;
    private SHVirtualDeviceRepository mVirtualDeviceRepository;
    private SHCCURepository mSHCCURepository;

    SmartHomeManager(SH smartClient) {
        this.mSmartclient = smartClient;
        mDevicerepository = smartClient.getRepositoryFactory().getDeviceRepository();
        mLocationrepository = smartClient.getRepositoryFactory().getLocationRepository();
        mVirtualDeviceRepository = smartClient.getRepositoryFactory().getVirtualDeviceRepository();
        mSHCCURepository = smartClient.getRepositoryFactory().getCcuRepository();
    }

    @Override
    public boolean sycnData() {
        Future<VoidResult> future = mSmartclient.asyncSyncData();
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public SHClientState getCurrentState() {
        return mSmartclient.getCurrentState();
    }

    @Override
    public List<Device> queryNewDevice() {
        return mDevicerepository.findDevicesByRoom(-1);
    }

    @Override
    public List<Device> queryNewDevice(SHDeviceType type) {
        return mDevicerepository.findDevices(-1, type);
    }

    @Override
    public List<Device> queryNewDevice(SHDeviceType type, SHDeviceSubType subType) {
        return mDevicerepository.findDevices(-1, type, subType);
    }

    @Override
    public List<Device> queryDevice(SHDeviceType type) {
        return mDevicerepository.findDevices(type);
    }

    @Override
    public List<Device> queryDevice(SHDeviceType type, SHDeviceSubType subType) {
        return mDevicerepository.findDevices(type, subType);
    }

    @Override
    public List<Device> queryZigbeeDevices() {
        return mDevicerepository.findZigbeeDevices();
    }

    @Override
    public Device queryZigbeeDevice(int id) {
        return mDevicerepository.findZigbeeDevice(id);
    }

    @Override
    public Device loadDevice(int id, SHDeviceType type) {
        return mDevicerepository.findDevice(id, type);
    }

    @Override
    public Device loadDevice(String id, SHDeviceType type) {
        return mDevicerepository.findDevice(id, type);
    }

    @Override
    public DeviceOnlineState findZigbeeDeviceOnlineState(String mac) {
        return mDevicerepository.findZigbeeDeviceOnlineState(mac);
    }

    @Override
    public SHDeviceRealType loadDeviceRealType(int id, SHDeviceType type) {
        return mDevicerepository.findDeviceRealtype(id, type);
    }

    @Override
    public Scene loadScene(int id) {
        return mVirtualDeviceRepository.findScene(id);
    }

    @Override
    public Scene findSceneWithPanel(int id) {
        return mVirtualDeviceRepository.findSceneWithPanel(id);
    }

    @Override
    public Group loadGroup(int id) {
        return mVirtualDeviceRepository.findGroup(id);
    }

    @Override
    public IFTTT loadRule(int id) {
        return mVirtualDeviceRepository.findRule(id);
    }

    @Override
    public IFTTTEX loadExRule(int id) {
        return mVirtualDeviceRepository.findExRule(id);
    }

    @Override
    public GetDevStatusLogResult queryDeviceLogs(int pageIdx, int pageSize, int id, String beginDay, String endDay) {
        Future<GetDevStatusLogResult> future = mSmartclient.asyncGetDevStatusLog(pageIdx, pageSize, id, beginDay, endDay);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public VoidResult deleteAlarmMsg(String key) {
        Future<VoidResult> future = mSmartclient.asyncDeleteAlarmMsg(key);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public GetDevInfoResult queryZigbeeDeviceInfo(int id) {
        Future<GetDevInfoResult> future = mSmartclient.asyncGetDeviceInfo(id);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public String queryDevicePowerById(int id) {
        Future<GetDevPowerResult> future = mSmartclient.asyncGetDevicePower(id);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get().getPower();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public GetAlarmRecordResult queryAlarmRecord(int pageNo, int pageSize) {
        Future<GetAlarmRecordResult> future = mSmartclient.asyncGetAlarmLog(pageNo, pageSize);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }

        return null;
    }


    @Override
    public GetDayPowerResult queryPowerByDay(int id, String start, String end) {
        Future<GetDayPowerResult> future = mSmartclient.asyncGetPowerByDay(id, start, end);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public GetMonthPowerResult queryPowerByMonth(int id, String start, String end) {
        Future<GetMonthPowerResult> future = mSmartclient.asyncGetPowerByMonth(id, start, end);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public GetYearPowerResult queryPowerByYear(int id, String start, String end) {
        Future<GetYearPowerResult> future = mSmartclient.asyncGetPowerByYear(id, start, end);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public GetCcuVersionResult queryCcuVersion() {
        Future<GetCcuVersionResult> future = mSmartclient.asyncGetCcuVersion();
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }

        return null;
    }

    @Override
    public GetCcuInfoResult queryCcuInfo() {
        Future<GetCcuInfoResult> future = mSmartclient.asyncGetCcuInfo();
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public boolean upgradeKitCcu(String url) {
        Future<VoidResult> future = mSmartclient.asyncKitCcuInstall(url);
        AsynTool.sync(future);
        return future.isSuccess();
    }


    @Override
    public GetLockUserListResult asyncLockUserList(int devId) {
        Future<GetLockUserListResult> future = mSmartclient.asyncLockUserList(devId);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public GetLockOpenRecordResult asyncLockOpenRecordList(int id, int pageIdx, int pageSize, String beginDay, String endDay) {
        Future<GetLockOpenRecordResult> future = mSmartclient.asyncLockOpenRecord(id, pageIdx, pageSize, beginDay, endDay);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public GetInfraredLastSendCodeResult getInfraredGetLastSendCode(int devId) {
        Future<GetInfraredLastSendCodeResult> future = mSmartclient.asyncInfraredGetLastSendCode(devId);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public VoidResult switchHomebridge(String id, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncSwitchHomebridge(id, on);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public GetHomebridgeStatusResult getHomebridgeStatus(String id) {
        Future<GetHomebridgeStatusResult> future = mSmartclient.asyncGetHomebridgeStatus(id);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public List<Device> findZigbeeDevicesByLast4Mac(String lastMac) {
        return mDevicerepository.findZigbeeDevicesByLast4Mac(lastMac);
    }

    @Override
    public List<Device> findDevicesByName(String devName) {
        return mDevicerepository.findDevicesByName(devName);
    }

    @Override
    public boolean setRoomDnd(int roomId, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncZoneDndSwitch(roomId, on);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public GetMusicListResult queryMusicList(int id) {
        Future<GetMusicListResult> future = mSmartclient.asyncGetCnwiseMusicList(id);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public GetMusicControllerStatusResult queryMusicStatus(int id) {
        Future<GetMusicControllerStatusResult> future = mSmartclient.asyncGetMusicControllerStatus(id);
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return null;
    }

    @Override
    public VoidResult restoreCcu(String fromCcuId, String url) {
        Future<VoidResult> future = mSmartclient.asyncRestoreCcu(fromCcuId, url);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult backupCcu() {
        Future<VoidResult> future = mSmartclient.asyncBackupCcu();
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }


    @Override
    public void lanCon() {
        mSmartclient.tryLanCon();
    }

    @Override
    public GetZigbeeDevPingResult pingZigbeeDev(int gwId, String[] devMacs) {
        Future<GetZigbeeDevPingResult> future = mSmartclient.asyncPingZigbeeDev(gwId, devMacs);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetDevHwInfoResult getDevicesHwInfo(String[] macs) {
        Future<GetDevHwInfoResult> future = mSmartclient.asyncGetDevicesHwInfo(macs);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Gateway findGetewayInfo(String mac) {
        return mDevicerepository.findGetwayInfo(mac);
    }

    @Override
    public VoidResult resetGwFouctoryMode(int gwId) {
        Future<VoidResult> future = mSmartclient.asyncResetGwFactoryMode(gwId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Room> queryAllRooms() {
        return mLocationrepository.findAllRooms();
    }

    @Override
    public Room queryRoom(int roomId) {
        return mLocationrepository.findRoomById(roomId);
    }

    @Override
    public Controller queryController(int devId) {
        return mDevicerepository.findController(devId);
    }

    @Override
    public List<Controller> queryAllControllers() {
        return mDevicerepository.findAllControllers();
    }

    @Override
    public List<Device> queryDevice(int roomId, String gwmac) {
        return mDevicerepository.findDevices(roomId, gwmac);
    }

    @Override
    public List<Device> queryDevice(String gwMac) {
        return mDevicerepository.findZigbeeDevicesByGwMac(gwMac);
    }

    public List<Device> findDeviceByMac(String mac) {
        return mDevicerepository.findZigbeeDevicesByMac(mac);
    }

    @Override
    public int findZigbeeDeviceProductId(String mac) {
        return mDevicerepository.findZigbeeDeviceProductId(mac);
    }

    @Override
    public List<Device> queryDevice(int roomId) {
        if (roomId == -1) {
            return mDevicerepository.findAllDevices();
        } else {
            return mDevicerepository.findDevicesByRoom(roomId);
        }
    }

    @Override
    public List<Device> queryDevice(int roomId, SHDeviceType type) {
        return mDevicerepository.findDevices(roomId, type);
    }

    @Override
    public List<Scene> queryScene(int roomId) {
        if (roomId == -1) {
            return mVirtualDeviceRepository.findAllScenes();
        } else {
            return mVirtualDeviceRepository.findSceneByRoom(roomId);
        }
    }


    @Override
    public List<Group> queryGroup() {
        return mVirtualDeviceRepository.findAllGroups();
    }

    @Override
    public List<IFTTT> queryIfttt() {
        return mVirtualDeviceRepository.findAllRules();
    }

    @Override
    public List<IFTTTEX> queryIftttEx() {
        return mVirtualDeviceRepository.findAllExRules();
    }

    @Override
    public int queryOnLightCount(List<Device> list) {
        int count = 0;
        List<Integer> list1 = new ArrayList<>();
        for (Device device : list) {
            if (isLightOn(device) && device.getRoomId() > 0) {
                if (device.getSubType().equals(SHDeviceSubType.ZIGBEE_LIGHT)) {
                    list1.add(device.getId());
                }
                count++;
            }
        }
        if (count > 0) {
            JsonArray array = getDeviceAppArgs(-1, null);
            List<Integer> hideid = new ArrayList<Integer>();
            if (array != null) {
                for (int i = 0; i < array.size(); i++) {
                    JsonObject obj = array.get(i).getAsJsonObject();
                    if (obj.get("arg_type").getAsString().equals("RoomHiddenZigbeeNodes") && obj.get("arg").isJsonArray()) {
                        JsonArray arg = obj.get("arg").getAsJsonArray();
                        for (int j = 0; j < arg.size(); j++) {
                            hideid.add(arg.get(j).getAsInt());
                        }
                        break;
                    }
                }
            }
            if (hideid != null && hideid.size() > 0) {
                int delCount = 0;
                for (Integer id : list1) {
                    if (hideid.contains(id)) {
                        delCount++;
                    }
                }
                count = count - delCount;
            }
        }
        return count;
    }

    private boolean isLightOn(Device device) {
        if (device.getStatus() == null)
            return false;

        if (device.getType().equals(SHDeviceType.ZIGBEE_Switch)
                && device.getSubType().equals(SHDeviceSubType.ZIGBEE_LIGHT)
                && ((ZigbeeSwitchStatus) device.getStatus()).isOn()) {
            ZigbeeDeviceStatus status = (ZigbeeDeviceStatus) device.getStatus();
            if (status != null && status.getOnlineState() != DeviceOnlineState.OFFLINE) {
                return true;
            }
        } else if (device.getType().equals(SHDeviceType.ZIGBEE_Dimmer)) {
            ZigbeeDimmerStatus status = (ZigbeeDimmerStatus) device.getStatus();
            if (status.isOn()) {
                if (status != null && status.getOnlineState() != DeviceOnlineState.OFFLINE) {
                    return true;
                }
            }
        } else if (device.getType().equals(SHDeviceType.NET_HueLight)) {
            HueLightStatus status = (HueLightStatus) device.getStatus();
            if (status.isOn() && status.isOnline()) {
                return true;
            }
        } else if (device.getType().equals(SHDeviceType.NET_KonkeLight)) {
            KonkeLightStatus status = (KonkeLightStatus) device.getStatus();
            if (status.isOn() && status.isOnline()) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int queryOpenCurtainCount(List<Device> list) {
        int count = 0;
        if (list == null) {
            return count;
        }

        for (Device device : list) {
            if (device.getStatus() == null) {
                continue;
            }
            if (device.getType().equals(SHDeviceType.ZIGBEE_Motor)
                    && device.getSubType().equals(SHDeviceSubType.ZIGBEE_CURTAIN)
                    && ((ZigbeeMotorStatus) device.getStatus()).getStatus().equals(ZigbeeMotorStatus.STATUS.OPEN)) {
                count++;
            } else if (device.getType().equals(SHDeviceType.ZIGBEE_Motor)
                    && device.getSubType().equals(SHDeviceSubType.ZIGBEE_DooYa)) {
                ZigbeeDooYaStatus status = (ZigbeeDooYaStatus) device.getStatus();
                if (status.isRouteCfg() && status.getMotorPos() > 0) {
                    count++;
                }
            }
        }
        return count;
    }

    @Override
    public double queryAvgTemp(List<Device> list) {
        double temp = 0;
        double num;
        int count = 0;
        if (list == null || list.isEmpty()) {
            return ZigbeeNumSensorStatus.UNKNOWN_VAULE;
        }
        for (Device device : list) {
            if (device.getStatus() == null) {
                continue;
            }
            if (device.getType().equals(SHDeviceType.ZIGBEE_NumSensor)
                    && device.getSubType().equals(SHDeviceSubType.ZIGBEE_TempSensor)) {
                num = ((ZigbeeNumSensorStatus) device.getStatus()).getNum();
                if (num != ZigbeeNumSensorStatus.UNKNOWN_VAULE) {
                    count++;
                    temp += num;
                }
            }
        }
        if (count > 0) {
            return temp / count;
        }
        return ZigbeeNumSensorStatus.UNKNOWN_VAULE;
    }

    @Override
    public double queryAvgHumi(List<Device> list) {
        double temp = 0;
        double num;
        int count = 0;
        if (list == null || list.isEmpty()) {
            return ZigbeeNumSensorStatus.UNKNOWN_VAULE;
        }
        for (Device device : list) {
            if (device.getStatus() == null) {
                continue;
            }
            if (device.getType().equals(SHDeviceType.ZIGBEE_NumSensor)
                    && device.getSubType().equals(SHDeviceSubType.ZIGBEE_HumiSensor)) {
                num = ((ZigbeeNumSensorStatus) device.getStatus()).getNum();
                if (num != ZigbeeNumSensorStatus.UNKNOWN_VAULE) {
                    count++;
                    temp += num;
                }
            }
        }
        if (count > 0)
            return temp / count;
        return ZigbeeNumSensorStatus.UNKNOWN_VAULE;
    }

    @Override
    public boolean doorIsOpen(List<Device> devices) {
        if (devices == null || devices.size() == 0) {
            return false;
        }
        for (Device device : devices) {
            if (device.getType().equals(SHDeviceType.ZIGBEE_DoorContact)) {
                if (((ZigbeeDoorContactStatus) (device.getStatus())).isOn()) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean hasPerseon(List<Device> devices) {
        if (devices == null || devices.size() == 0) {
            return false;
        }
        for (Device device : devices) {
            if (device.getRealType().equals(SHDeviceRealType.KONKE_KK_HumanbodyInfraredSensor) ||
                    device.getRealType().equals(SHDeviceRealType.KONKE_ZIGBEE_HUMANBODYINFRAREDSENSOR) ||
                    device.getRealType().equals(SHDeviceRealType.KONKE_ZIGBEE_SMARTBODYSENSOR)) {

                if (((ZigbeeBoolSensorStatus) (device.getStatus())).isNormal()) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public ArmingState queryArmingStatus() {
        return mSHCCURepository.getArmingStatus();
    }

    @Override
    public int[] getCustomGuardZones() {
        return mSHCCURepository.getGuardZones();
    }

    @Override
    public boolean setCustomZoneGuard(int[] roomIds) {
        Future<VoidResult> future = mSmartclient.asynSetCustomZoneGuard(roomIds);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public int getSecurityLeaveHomeDelay() {
        Future<GetLeaveHomeDelayResult> future = mSmartclient.asyncGetSecurityLeaveHomeDelay();
        AsynTool.sync(future);
        if (future.isSuccess())
            try {
                return future.get().getDelay();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        return 0;
    }

    @Override
    public boolean setSecurityLeaveHomeDelay(int delay) {
        Future<VoidResult> future = mSmartclient.asyncSecurityLeaveHomeDelay(delay);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setSecurityLeaveHomeDelay(ArmingState armingState) {
        Future<VoidResult> future = mSmartclient.asyncSecurityUpdateArmingState(armingState);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public String getCurCcuVersion() {
        return mSHCCURepository.getCurCcuVersion();
    }

    @Override
    public SHGuardSensorType queryGuardSensorType(int devId) {
        return mDevicerepository.findGuardSensorType(devId);
    }

    @Override
    public Room addRoom(int floorId, String roomName, String roomIcon, int roomPos) {
        Future<AddRoomResult> future = mSmartclient.asyncAddRoom(roomName, roomIcon, FloorId.parseId(floorId), String.valueOf(roomPos));
        AsynTool.sync(future);
        try {
            if (future.isSuccess()) {
                XLog.i("add room success");
                AddRoomResult result = future.get();
                int roomId = result.getRoomId();
                Room room = mLocationrepository.findRoomById(roomId);
                return room;
            }
        } catch (InterruptedException e) {
            XLog.e(e);
        } catch (ExecutionException e) {
            XLog.e(e);
        }
        XLog.e("add room fail");
        return null;
    }

    @Override
    public AddSceneResult addScene(String sceneType, String sceneImange, String name, int roomId) {
        Future<AddSceneResult> future = mSmartclient.asyncAddScene(name, Integer.valueOf(sceneType), sceneImange, roomId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            XLog.e(e);
        } catch (ExecutionException e) {
            XLog.e(e);
        }
        return null;
    }

    @Override
    public IFTTT addIFttt(String name, int roomId, boolean notificationEnable, boolean ruleEnable, List<Condition> conditionList, List<Action> actionList) {
        Future<VoidResult> future = mSmartclient.asyncAddIfttt(name, roomId, notificationEnable, ruleEnable, conditionList, actionList);
        AsynTool.sync(future);
        try {
            if (future.isSuccess()) {
                XLog.i("add ifttt success");
                VoidResult result = future.get();
                int id = result.getArg().getAsJsonPrimitive().getAsInt();
                return mVirtualDeviceRepository.findRule(id);
            }
        } catch (InterruptedException e) {
            XLog.e(e);
        } catch (ExecutionException e) {
            XLog.e(e);
        }
        XLog.e("add ifttt fail");
        return null;
    }

    @Override
    public IFTTTEX addIFtttEx(String name, int roomId, boolean notificationEnable, boolean ruleEnable, List<Condition> conditionList, List<Limit> limitList,
                              List<Action> actionList) {
        Future<AddIftttResult> future = mSmartclient.asyncAddIftttEx(name, roomId, notificationEnable, ruleEnable, conditionList, limitList, actionList);
        AsynTool.sync(future);
        try {
            if (future.isSuccess()) {
                XLog.i("add iftttex success");
                int id = future.get().getRuleId();
                return mVirtualDeviceRepository.findExRule(id);
            }
        } catch (InterruptedException e) {
            XLog.e(e);
        } catch (ExecutionException e) {
            XLog.e(e);
        }
        XLog.e("add iftttex fail");
        return null;
    }

    @Override
    public void searchIPC() {
        mSmartclient.asyncSearchIpc();
    }

    @Override
    public boolean setGwName(int id, String name) {
        Future<VoidResult> future = mSmartclient.asyncEditGwName(id, name);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public Room editRoom(int roomId, int floorId, String roomName, String roomIcon, int roomPos) {
        Future<VoidResult> future = mSmartclient.asyncEditRoom(roomId, roomName, roomIcon, FloorId.parseId(floorId), String.valueOf(roomPos));
        AsynTool.sync(future);
        if (future.isSuccess()) {
            XLog.i("edit room success");
            Room room = mLocationrepository.findRoomById(roomId);
            return room;
        }
        XLog.e("edit room fail");
        return null;
    }

    @Override
    public Scene editScene(int id, String sceneType, String sceneImange, String name, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncEditScene(id, name, Integer.valueOf(sceneType), sceneImange, roomId);
        AsynTool.sync(future);
        if (future.isSuccess()) {
            XLog.i("edit scene success");
            return mVirtualDeviceRepository.findScene(id);
        }
        XLog.e("edit scene fail");
        return null;
    }

    @Override
    public boolean setSceneTimer(int id, boolean enableTimer, String time, List<String> week) {
        Future<VoidResult> future = mSmartclient.asyncSetSceneTimer(id, enableTimer, time, week);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setSceneAction(int id, List<Action> actionList) {
        Future<VoidResult> future = mSmartclient.asyncSetSceneAction(id, actionList);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public Group editGroup(int id, String name, List<String> nodeIds) {
        Future<VoidResult> future = mSmartclient.asyncAddOrUpdateGroup(id, name, nodeIds);
        AsynTool.sync(future);
        if (future.isSuccess()) {
            XLog.i("edit group success");
            return mVirtualDeviceRepository.findGroup(id);
        }
        return null;
    }

    @Override
    public IFTTT editIFttt(int id, String name, int roomId, boolean notificationEnable, boolean ruleEnable, List<Condition> conditionList, List<Action> actionList) {
        Future<VoidResult> future = mSmartclient.asyncEditIfttt(id, name, roomId, notificationEnable, ruleEnable, conditionList, actionList);
        AsynTool.sync(future);
        if (future.isSuccess()) {
            XLog.i("edit ifttt success");
            return mVirtualDeviceRepository.findRule(id);
        }
        XLog.e("edit ifttt fail");
        return null;
    }

    @Override
    public IFTTTEX editIFtttEx(int id, String name, int roomId, boolean notificationEnable, boolean ruleEnable, List<Condition> conditionList,
                               List<Limit> limitList, List<Action> actionList) {
        Future<VoidResult> future = mSmartclient.asyncEditIftttEx(id, name, roomId, notificationEnable, ruleEnable, conditionList, limitList, actionList);
        AsynTool.sync(future);
        if (future.isSuccess()) {
            XLog.i("edit ifttt ex success");
            return mVirtualDeviceRepository.findExRule(id);
        }
        XLog.e("edit ifttt ex fail");
        return null;
    }

    @Override
    public boolean enableIfttt(int id, boolean enable) {
        Future<VoidResult> future = mSmartclient.asyncEnableIfttt(id, enable);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean enableIftttEx(int id, boolean enable) {
        Future<VoidResult> future = mSmartclient.asyncEnableIftttEx(id, enable);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean asyncSetShortcutPanelAction(int id, List<ShortcutPanelConfig> configList) {
        Future<VoidResult> future = mSmartclient.asyncSetShortcutPanelAction(id, configList);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public void asyncActiveShortcutPanel(int id, int buttonId) {
        mSmartclient.asyncActiveShortcutPanel(id, buttonId);
    }

    @Override
    public boolean delRoom(int roomId) {
        Future<VoidResult> future = mSmartclient.asyncDelRoom(roomId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean delGateway(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelGw(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean upgradeGateway(int id) {
        Future<VoidResult> future = mSmartclient.asyncUpgradGw(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean upgradeGateway9531(int gwId, String url) {
        Future<VoidResult> future = mSmartclient.asyncUpgradGw9531(gwId, url);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setMusicControllerZoneName(int id, int zoneId, String zoneName) {
        Future<VoidResult> future = mSmartclient.asyncEditMusicControllerZoneName(id, zoneId, zoneName);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public Device editDevice(SHDeviceType type, int devId, int roomId, String devName, String devIcon) {
        Future<VoidResult> future = mSmartclient.asyncEditDevice(devId, devName, devIcon, roomId);
        return editDeviceSync(devId, future, type);
    }

    @Override
    public VoidResult replaceDevice(String newDevMac, String oldDevMac, String gwMac) {
        Future<VoidResult> future = mSmartclient.asyncReplaceDevice(newDevMac, oldDevMac, gwMac);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }


    @Override
    public Device editSensor(SHDeviceType type, int devId, int roomId, String devName, String devIcon, SHGuardSensorType sensorType) {
        Future<VoidResult> future = mSmartclient.asyncEditGuardSensor(devId, devName, devIcon, roomId, sensorType);
        return editDeviceSync(devId, future, type);
    }

    @Override
    public boolean setSensorRunmode(int id, ZigbeeUniversalBoosSensorStatus.ModuleType type) {
        Future<VoidResult> future = mSmartclient.asyncSetUniversalSensorboolRunmode(id, type, "255");
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean asyncBindScene(int id, int sceneid) {
        Future<VoidResult> future = mSmartclient.asyncBindScene(id, sceneid);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public Device editKSocket(int devId, String devName, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncEditKonkeSocket(devId, devName, roomId);
        return editDeviceSync(devId, future, SHDeviceType.NET_KonkeSocket);
    }

    @Override
    public Device editKLight(int devId, String devName, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncEditKonkeLight(devId, devName, roomId);
        return editDeviceSync(devId, future, SHDeviceType.NET_KonkeLight);
    }

    @Override
    public Device editHueLight(int devId, String devName, String icon, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncEditHueLight(devId, devName, icon, roomId);
        return editDeviceSync(devId, future, SHDeviceType.NET_HueLight);
    }

    @Override
    public Device editJufengIPC(int devId, String devName, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncEditIpc(devId, devName, roomId);
        return editDeviceSync(devId, future, SHDeviceType.NET_JuFengIpc);
    }

    @Override
    public Device editMusicController(int devId, String name, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncEditMusicController(devId, roomId, name);
        return editDeviceSync(devId, future, SHDeviceType.NET_CnwiseMusicController);
    }

    @Override
    public Device editKonkeHumidifier(int devId, String name, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncEditKonkeHumidifier(devId, roomId, name);
        return editDeviceSync(devId, future, SHDeviceType.NET_KonkeHumidifier);
    }

    @Override
    public Device editKonkeAircleaner(int devId, String name, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncEditKonkeAircleaner(devId, roomId, name);
        return editDeviceSync(devId, future, SHDeviceType.NET_KonkeAircleaner);
    }

    @Override
    public boolean asyncEditLockUser(int id, int userId, int openType, String nickName) {
        Future<VoidResult> future = mSmartclient.asyncEditLockUser(id, userId, openType, nickName);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean editLockPassword(int id, String oldpwd, String newpwd) {
        Future<VoidResult> future = mSmartclient.asyncEditLockPassword(id, oldpwd, newpwd);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public Device asyncEditModbus(int id, int roomId, String name) {
        Future<VoidResult> future = mSmartclient.asyncEditModbus(id, roomId, name);
        return editDeviceSync(id, future, SHDeviceType.NET_ModBusDevice);
    }

    @Override
    public Device asyncEditDaikinIndoorUnit(int id, int roomId, String name) {
        Future<VoidResult> future = mSmartclient.asyncEditDaikinIndoorUnit(id, roomId, name);
        return editDeviceSync(id, future, SHDeviceType.NET_DaikinIndoorUnit);
    }

    @Override
    public Device asyncEditCentralAcGw(int id, int roomId, String name) {
        Future<VoidResult> future = mSmartclient.asyncEditCentralAcGw(id, roomId, name);
        return editDeviceSync(id, future, SHDeviceType.NET_CENTRAL_AC_Gateway);
    }

    @Override
    public Device asyncEditCentralAcIndoorUnit(int id, int roomId, String name) {
        Future<VoidResult> future = mSmartclient.asyncEditCentralAcIndoorUnit(id, roomId, name);
        return editDeviceSync(id, future, SHDeviceType.NET_CENTRAL_AC_IndoorUnit);
    }

    @Override
    public GetGwWorkmodeResult getGwWorkmode(int gwId) {
        Future<GetGwWorkmodeResult> future = mSmartclient.asyncGetGwWorkmode(gwId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setGwWorkmode(int gwId, int workMode) {
        Future<VoidResult> future = mSmartclient.asyncSetGwWorkmode(gwId, workMode);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetGwWhitelistResult getGwWhitelist(int gwId) {
        Future<GetGwWhitelistResult> future = mSmartclient.asyncGetGwWhitelist(gwId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult addGwWhiteList(int gwId, List<WhiteDev> devList) {
        Future<VoidResult> future = mSmartclient.asyncAddGwWhiteList(gwId, devList);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult delGwWhiteList(int gwId, String[] devMacs) {
        Future<VoidResult> future = mSmartclient.asyncDelGwWhiteList(gwId, devMacs);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean asyncDelModbus(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelModbus(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean asyncDelCenralAcGw(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelCentralAcGw(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean asyncDelDaikinIndoorUnit(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelDaikinIndoorUnit(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean asyncOptDaikinIndoorUnit(int id, boolean on, String runModel, String speed, int temp) {
        Future<VoidResult> future = mSmartclient.asyncOptDaikinIndoorUnit(id, on, runModel, speed, temp);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean asyncOptCentralAcGwIndoorUnit(int id, boolean on, String runModel, String speed, int temp) {
        Future<VoidResult> future = mSmartclient.asyncOptCentralAcIndoorUnit(id, on, runModel, speed, temp);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean deleteDevice(String mac) {
        Future<VoidResult> future = mSmartclient.asyncDelNode(mac);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean deleteKSocket(int devId) {
        Future<VoidResult> future = mSmartclient.asyncDelKonkeSocket(devId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean deleteKLight(int devId) {
        Future<VoidResult> future = mSmartclient.asyncDelKonkeLight(devId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean deleteKonkeHumidifier(int devId) {
        Future<VoidResult> future = mSmartclient.asyncDelKonkeHumidifier(devId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean deleteKonkeAircleaner(int devId) {
        Future<VoidResult> future = mSmartclient.asyncDelKonkeAircleaner(devId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean deleteHueLight(int devId) {
        Future<VoidResult> future = mSmartclient.asyncDelHueLight(devId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean deleteJufengIPC(int devId) {
        Future<VoidResult> future = mSmartclient.asyncDelIpc(devId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean deleteScene(int sceneId) {
        Future<VoidResult> future = mSmartclient.asyncDelScene(sceneId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean delGroup(int gid) {
        Future<VoidResult> future = mSmartclient.asyncDelGroup(gid);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean delIFttt(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelIfttt(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean delIFtttEx(int ruleId) {
        Future<VoidResult> future = mSmartclient.asyncDelIftttEx(ruleId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean deleteMusicController(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelMusicController(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public void cancelWarning() {
        mSmartclient.asyncSecurityCancelWarning();
    }

    @Override
    public void readAlarmMsg(String key) {
        mSmartclient.asyncReadAlarmMsg(key);
    }

    @Override
    public void readAlarm(String startTime, String endTime) {
        mSmartclient.asyncReadAlarmMsg(startTime, endTime);
    }

    @Override
    public void clearSosAlarm(int id) {
        mSmartclient.asyncClearSosAlarm(id);
    }

    @Override
    public boolean inShortCutPanel(int nodeId) {
        return mDevicerepository.inShortCutPanel(nodeId);
    }

    @Override
    public boolean inController(int nodeId) {
        return mDevicerepository.inController(nodeId);
    }

    @Override
    public boolean inLock(int nodeId) {
        return mDevicerepository.isDoorcontactInLock(nodeId);
    }

    @Override
    public boolean inGroup(int nodeId) {
        return mVirtualDeviceRepository.inGroup(nodeId);
    }

    @Override
    public List<Group> findGroupsByDeviceId(int nodeId) {
        return mVirtualDeviceRepository.findGroupsByDeviceId(nodeId);
    }

    @Override
    public boolean inScene(SHDeviceType type, int nodeId) {
        return mVirtualDeviceRepository.inScene(type, nodeId);
    }

    @Override
    public boolean inIFTTT(SHDeviceType type, int nodeId) {
        return mVirtualDeviceRepository.inIFTTTEx(type, nodeId);
    }

    @Override
    public boolean openGatewayChannel(int gwId) {
        Future<VoidResult> future = mSmartclient.asyncGatewayOpenNetChannel(gwId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean closeGatewayChannel(int id) {
        Future<VoidResult> future = mSmartclient.asyncGatewayCloseNetChannel(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public TextIndicatorResult getTextIndicatorStatus(int nodeId) {
        Future<TextIndicatorResult> future = mSmartclient.asyncGetTextIndicatorStatus(nodeId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setTextIndicatorArgs(int nodeId, int offTime) {
        Future<VoidResult> future = mSmartclient.asyncSetTextIndicatorArgs(nodeId, offTime);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean openHueGatewayChannel(int id) {
        Future<VoidResult> future = mSmartclient.asyncOpenHueGwChannel(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean activateHueGateway(int id) {
        Future<VoidResult> future = mSmartclient.asyncActiveHueGw(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public void switchArmingState(ArmingState state) {
        mSmartclient.asyncSecurityUpdateArmingState(state);
    }

    @Override
    public void switchRoomLights(int roomId, boolean on) {
        mSmartclient.asyncZoneLightSwitch(roomId, on);
    }

    @Override
    public void optRoomCurtains(int roomId, MotorOpt opt) {
        mSmartclient.asyncZoneCurtainOpt(roomId, opt);
    }


    @Override
    public void switchOpt(int id, boolean on) {
        mSmartclient.asyncSwitchOpt(id, on);
    }

    @Override
    public boolean switchSocketChannel(int id, int channel, boolean on) {
        List<ZigbeeExtensionSocketStatus.MultiSocketStatus> multiSocketStatuses = new ArrayList<>();
        multiSocketStatuses.add(new ZigbeeExtensionSocketStatus.MultiSocketStatus(channel, on));
        Future<VoidResult> future = mSmartclient.asyncMultiSocketsSwitch(id, multiSocketStatuses);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public VoidResult adjustAlertorVolume(int id, int vol) {
        Future<VoidResult> future = mSmartclient.asyncAdjustAlertorVolume(id, vol);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult driveAirerLightOpt(int id, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncDriveAirerLightOpt(id, on);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult driveAirerMotorOpt(int id, MotorOpt opt) {
        Future<VoidResult> future = mSmartclient.asyncDriveAirerMotorOpt(id, opt);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult driveAirerAirDryOpt(int id, boolean on, int timeInMinutes) {
        Future<VoidResult> future = mSmartclient.asyncDriveAirerAirDryOpt(id, on, timeInMinutes);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult driveAirerStovingOpt(int id, boolean on, int timeInMinutes) {
        Future<VoidResult> future = mSmartclient.asyncDriveAirerStovingOpt(id, on, timeInMinutes);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult driveAirerSterilizeOpt(int id, boolean on, int timeInMinutes) {
        Future<VoidResult> future = mSmartclient.asyncDriveAirerSterilizeOpt(id, on, timeInMinutes);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult switchDevice(int id, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncSwitchOpt(id, on);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFloorHeatingTemp(int id, double temp) {
        Future<VoidResult> future = mSmartclient.asyncSetFloorheatingWorkTemperature(id, temp);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFloorHeatingTemp(int id, int temp) {
        Future<VoidResult> future = mSmartclient.asyncSetFloorheatingWorkTemperature(id, temp);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFloorHeatingMode(int id, boolean autoElseManual) {
        Future<VoidResult> future = mSmartclient.asyncSetFloorheatingWorkMode(id, autoElseManual ?
                ZigbeeFloorHeatingStatus.RUNMODEL.AUTO : ZigbeeFloorHeatingStatus.RUNMODEL.MANUAL);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFloorHeatingPlan(int id, List<ZigbeeFloorHeatingStatus.SettingZone> zoneList) {
        Future<VoidResult> future = mSmartclient.asyncSetFloorheatingWorkPlan(id, zoneList);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFloorhearManagerOpt(int id, int[] channal, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncFloorHeatingManagerOpt(id, channal, on);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetFloorheatingStatusResult getFloorheatDevStatu(int id) {
        Future<GetFloorheatingStatusResult> future = mSmartclient.asyncGetFloorheatingDevStatus(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFloorheatingDevTemp(int id, double temp) {
        Future<VoidResult> future = mSmartclient.asyncSetFloorheatingTemperature(id, temp);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFloorheatingDevLock(int id, boolean lock) {
        Future<VoidResult> future = mSmartclient.asyncSetFloorheatingLock(id, lock);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFloorheatingOffTime(int id, String offTime) {
        Future<VoidResult> future = mSmartclient.asyncSetFloorheatingOffTime(id, offTime);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;

    }

    @Override
    public VoidResult setFloorheatingLockStatus(int id, boolean lock) {
        Future<VoidResult> future = mSmartclient.asyncSetFloorheatingSetLockStatus(id, lock);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public FloorheatingConfigArgResult getFloorheatingConfigArg(int id) {
        Future<FloorheatingConfigArgResult> future = mSmartclient.asyncGetFloorheatingConfigArg(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean isFloorHeatingSingleDayOff(int id) {
        Future<FloorheatingArgsResult> future = mSmartclient.asyncGetFloorheatingArgs(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess()) {
                return future.get().getDayOffType() == 2;
            }
        } catch (Exception e) {

        }
        return false;
    }

    @Override
    public boolean freshAirSwitch(int id, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncFreshAirSwitch(id, on);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean freshAirSetRunModel(int id, ZigbeeFreshAirStatus.RUNMODEL runModel) {
        Future<VoidResult> future = mSmartclient.asyncFreshAirSetRunModel(id, runModel);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean freshAirSetWorkModel(int id, ZigbeeFreshAirStatus.WORKMODEL workModel) {
        Future<VoidResult> future = mSmartclient.asyncFreshAirSetWorkModel(id, workModel);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean freshAirSetSpeed(int id, ZigbeeFreshAirStatus.SPEEDLELVEL speed) {
        Future<VoidResult> future = mSmartclient.asyncFreshAirSetSpeed(id, speed);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public String freshAirGetCo2(int id) {
        Future<GetFreshAirValueResult> future = mSmartclient.asyncFreshAirGetCo2(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess()) {
                return future.get().getValue();
            }
        } catch (Exception e) {

        }
        return null;
    }

    @Override
    public String freshAirGetPm25(int id) {
        Future<GetFreshAirValueResult> future = mSmartclient.asyncFreshAirGetPm25(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess()) {
                return future.get().getValue();
            }
        } catch (Exception e) {

        }
        return null;
    }

    @Override
    public boolean freshAirSetFilterScreenWorkTime(int id, int timeIn100h) {
        Future<VoidResult> future = mSmartclient.asyncFreshAirSetFilterScreenWorkTime(id, timeIn100h);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean freshAirResetFilterScreen(int id) {
        Future<VoidResult> future = mSmartclient.asyncFreshAirResetFilterScreen(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public VoidResult freshAirSetLockStatus(int id, boolean lock) {
        Future<VoidResult> future = mSmartclient.asyncFreshAirSetLockStatus(id, lock);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFreshAirOffTime(int id, String timeOff) {
        Future<VoidResult> future = mSmartclient.asyncSetChopinFreshAirTimeOff(id, timeOff);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFreshAitFilterAlarmTime(int id, boolean reset, int alarmTime) {
        Future<VoidResult> future = mSmartclient.asyncSetChopinFreshAirFilterScreenTime(id, reset, alarmTime);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public ChopinFreshAirConfigArgsResult getChopinFreshAirConfigArgs(int id) {
        Future<ChopinFreshAirConfigArgsResult> future = mSmartclient.asyncGetChopinFreshAirConfigArgs(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetFreshAirStatusResult getFreshAirStatus(int id) {
        Future<GetFreshAirStatusResult> future = mSmartclient.asyncGetFreshAirDevStatu(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFreshAirDevMode(int id, int mode) {
        Future<VoidResult> future = mSmartclient.asyncSetFreshAirDevMode(id, mode);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFreshAirDevSpeed(int id, int speed) {
        Future<VoidResult> future = mSmartclient.asyncSetFreshAirDevSpeed(id, speed);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult resetFreshAirDevFilterTime(int id) {
        Future<VoidResult> future = mSmartclient.asyncResetFreshAirDevFilterTime(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setFreshAirDevFilterAlarmTime(int id, int time) {
        Future<VoidResult> future = mSmartclient.asyncSetFreshAirDevFilterAlarmTime(id, time);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult delFreshAirDev(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelFreshAirDev(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean adjustDimmerIlum(int id, int bri) {
        Future<VoidResult> future = mSmartclient.asyncDimmerAdjustLuminance(id, bri);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean adjustDimmerWhiteIlum(int id, int bri) {
        Future<VoidResult> future = mSmartclient.asyncDimmerAdjustWhiteLuminance(id, bri);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public VoidResult setDimmerRealIlum(int id, int bri) {
        Future<VoidResult> future = mSmartclient.asyncDimmerAdjustRealLuminace(id, bri);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetDimmableLightConfigResult getdimmableLightConfig(int id) {
        Future<GetDimmableLightConfigResult> future = mSmartclient.asyncGetDimmableLightConfig(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setDimmableLightConfig(int id, int softOn, int briLow, int briHigh) {
        Future<VoidResult> future = mSmartclient.asyncSetDimmableLightConfig(id, softOn, briLow, briHigh);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean adjustDimmerColor(int id, int[] rgb) {
        Future<VoidResult> future = mSmartclient.asyncDimmerAdjustColor(id, rgb);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean adjustRgbwPickedColor(int id, int modeId, int[] rgb, int bri, int whiteBri) {
        Future<VoidResult> future = mSmartclient.asyncDimmerSetPickedColorMode(id, modeId, rgb, bri, whiteBri);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean adjustRgbwDymanicColor(int id, int modeId) {
        Future<VoidResult> future = mSmartclient.asyncDimmerSetDynamicColorMode(id, modeId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public JsonArray getDeviceAppArgs(int id, SHDeviceType type) {
        Future<GetDevAppArgsResult> future = mSmartclient.asyncGetDevAppArgs(id, type);
        AsynTool.sync(future);
        try {
            if (future.isSuccess()) {
                return future.get().getArgs();
            }
        } catch (Exception e) {
            XLog.e("app_arg   exception");
        }
        return null;
    }

    @Override
    public boolean setDeviceAppArgs(int id, SHDeviceType devType, JsonArray args) {
        Future<VoidResult> future = mSmartclient.asyncSetDevAppArgs(id, devType, args);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setDeviceAppArg(int id, SHDeviceType devType, String argType, JsonElement argValue) {
        Future<VoidResult> future = mSmartclient.asyncSetDevAppArgWithType(id, devType, argType, argValue);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setDeviceCcuArg(int id, SHDeviceType devType, String argType, JsonElement argValue) {
        Future<VoidResult> future = mSmartclient.asyncSetDevCCUArgs(id, devType, (JsonArray) argValue);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setSocketPowerConfig(int devId, String power, boolean powerOff, boolean powerRemember) {
        if (mSmartclient == null) {
            return false;
        }
        Future<VoidResult> future = mSmartclient.asyncSetSocketRunArgs(devId, powerRemember, powerOff, power, "1");
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public GetSocketRunArgsResult getSocketPowerConfig(int devId) {
        Future<GetSocketRunArgsResult> future = mSmartclient.asyncGetSocketRunArgs(devId);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Boolean identify(int id) {
        Future<VoidResult> future = mSmartclient.asyncIdentifyDevice(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public Boolean closeAlertor(int id) {
        Future<VoidResult> future = mSmartclient.asyncCloseAlertor(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public void ksocketOpt(int id, boolean on) {
        mSmartclient.asyncKonkeSocketSwitch(id, on);
    }

    @Override
    public Boolean zigbeekonkesocketOpt(int id, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncZigbeeSocketLightSwitch(id, on);
        AsynTool.sync(future);
        return future.isSuccess();

    }

    @Override
    public boolean klockOpt(int id, String password, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncLockSwitch(id, password, on);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public VoidResult codedLockOpt(int id, String password, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncLockSwitch(id, password, on);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }


    @Override
    public void ksocketUsbOpt(int id, boolean on) {
        mSmartclient.asyncKonkeUsbSwitch(id, on);
    }

    @Override
    public void ksocketLightOpt(int id, boolean on) {
        mSmartclient.asyncKonkeNightLightSwitch(id, on);
    }

    @Override
    public void sceneOpt(int sceneId) {
        mSmartclient.asyncSceneExecute(sceneId);
    }

    @Override
    public void motorOpt(int devId, String operation) {
        mSmartclient.asyncMotorOpt(devId, MotorOpt.valueOf(operation));
    }

    @Override
    public boolean dooyaSeek(int devId, int pos) {
        Future<VoidResult> future = mSmartclient.asyncDooyaMotorSeek(devId, pos);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean dooyaRouteCfg(int devId) {
        Future<VoidResult> future = mSmartclient.asyncDooyaRouteConfig(devId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setDooyaReverse(int devId, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncDooyaSetReverse(devId, on);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean getDooyaReverse(int devId) {
        Future<DooyaReverseResult> future = mSmartclient.asyncDooyaGetReverse(devId);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get().isReverseOn();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public VoidResult setMotorSmartConfig(int devId, String cmd, String cmdArg) {
        Future<VoidResult> future = mSmartclient.asyncMotorSmartConfig(devId, cmd, cmdArg);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void hueOpt(int devId, boolean on, int bri, double[] xy) {
        mSmartclient.asyncHueLightOpt(devId, on, xy, bri);
    }

    @Override
    public void klightOpt(int devId, String mode, boolean on, int bri, int[] rgb, int speed) {
        String curVersion = "2.19.0";//mSmartclient.getRepositoryFactory().getCcuRepository().getCurCcuVersion();

        if ("FLOW".equals(mode)) {
            mSmartclient.asyncSetKLightFlowMode(devId, speed, on);
        } else {
            if (TextUtils.equals("2.18.0", curVersion) || StringUtils.isNewVersion("2.18.0", curVersion)) {
                mSmartclient.asyncSetKLightNormalMode(devId, mode, rgb, bri, on);
            } else {
                mSmartclient.asyncKongkeLightOpt(devId, on, rgb, bri);
            }
        }
    }

    @Override
    public void infraredOpt(int devId, int code) {
        mSmartclient.asyncInfraredTransmitterSendCode(devId, code);
    }

    @Override
    public boolean sendInfrared(int devId, int code) {
        Future<VoidResult> future = mSmartclient.asyncInfraredTransmitterSendCode(devId, code);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean rfOpt(int devId, int code) {
        Future<VoidResult> future = mSmartclient.asyncRFTransmitterSendCode(devId, code);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public void asyncLearnInfrared(int id, int code) {
        mSmartclient.asyncLearnInfrared(id, code);
    }

    @Override
    public void asyncLearnRF(int id, int code) {
        mSmartclient.asyncLearnRF(id, code);
    }

    @Override
    public GetDevDetectedPowerResult getDevDetectPowerResult(int id) {
        Future<GetDevDetectedPowerResult> future = mSmartclient.asyncGetDevDetectPowerResult(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean setDevDetectPowerByHand(int id, String standby, String running) {
        Future<VoidResult> future = mSmartclient.asyncSetDevPowerByHand(id, standby, running);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean activeDevDetectPower(int id) {
        Future<VoidResult> future = mSmartclient.asyncActiveDetectDevPower(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean saveInfrared(int id, int code) {
        Future<VoidResult> future = mSmartclient.asyncSaveInfrared(id, code);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean saveRF(int id, int code) {
        Future<VoidResult> future = mSmartclient.asyncSaveRF(id, code);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean saveInfraredRC(int id, List<Controller.Button> buttons) {
        Future<VoidResult> future = mSmartclient.asyncSaveInfraredRC(id, buttons);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean saveRFRC(int id, List<Controller.Button> buttons) {
        Future<VoidResult> future = mSmartclient.asyncSaveRFRC(id, buttons);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public GetCodelibResult getInfraredBindCodelib(int id) {
        Future<GetCodelibResult> future = mSmartclient.asyncGetBindCodelib(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void detectDevStandByPower(int id) {
        mSmartclient.asyncDetectDevStandbyPower(id);
    }

    @Override
    public void detectDevRunningPower(int id) {
        mSmartclient.asyncDetectDevRunningPower(id);
    }

    @Override
    public void controllerSmartSwitch(int id, boolean on) {
        mSmartclient.asyncInfraredSmartSwitch(id, on);
    }

    @Override
    public void asynResetInfraredBindCodelib(int id) {
        mSmartclient.asyncResetBindCodelib(id);
    }

    @Override
    public CodeLibBaseResult uploadCodelibToCloud(int codelibId) {
        Future<CodeLibBaseResult> future = mSmartclient.asyncUploadCodeLibToCloud(codelibId);
        AsynTool.sync(future);
        try {
            if (future != null)
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetLocalCodelibsResult getInfraredCodelib(String devType) {
        Future<GetLocalCodelibsResult> future = mSmartclient.asyncGetLocalCodelibs(devType);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public CodeLibBaseResult renameLocalCodelib(int codeId, String codelibName) {
        Future<CodeLibBaseResult> future = mSmartclient.asyncRenameLocalCodeLib(codeId, codelibName);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public CodeLibBindResult getCodelibBindInfrareds(int libId) {
        Future<CodeLibBindResult> future = mSmartclient.asyncGetCodelibBindDevice(libId);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public CodeLibBaseResult deleteInfraredCodelib(int libId) {
        Future<CodeLibBaseResult> future = mSmartclient.asyncDeleteCodelib(libId);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public AddCodeLibResult addInfraredCodelib(int devId, String devType, String libName, String codeLibLocation) {

        Future<AddCodeLibResult> future = mSmartclient.asyncCreateCodelib(devId, devType, libName, codeLibLocation);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;

    }

    @Override
    public CodeLibBaseResult testInfraredCodelib(int devId, int libId, int code) {
        Future<CodeLibBaseResult> future = mSmartclient.asyncTestCodelib(devId, libId, code);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public CodeLibBaseResult testCloudCodelib(int id, int codelibId, int codeId) {
        Future<CodeLibBaseResult> future = mSmartclient.asyncTestCloudCodelib(id, codelibId, codeId);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public CodeLibBaseResult prepareTestCloudlib(int codelibId) {
        Future<CodeLibBaseResult> future = mSmartclient.asyncPrepareTestCloudCodelib(codelibId);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public PrepareTestCodeLibResult downloadCodeFromCloud(int cloudLibId, int type, String devType, String devBound, String devModel, String name, String pcode) {
        Future<PrepareTestCodeLibResult> future = mSmartclient.asyncDownloadLibCodeFromCloud(cloudLibId, type, devType, devBound, devModel, name, pcode);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void matchInfraredCodelib(int libId, String devType) {
        mSmartclient.asyncMatchCloudCodelib(libId, devType);
    }

    @Override
    public CodeLibTaskResult getCodelibWorkingTask() {
        Future<CodeLibTaskResult> future = mSmartclient.asyncGetCodelibTaskInfo();
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetCodelibButtonsResult getCodelibUiButtons(int libId) {
        Future<GetCodelibButtonsResult> future = mSmartclient.asyncGetCodelibButtons(libId);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void asynUploadCodelib(int id, int libId) {
        mSmartclient.asyncUploadCodelib(id, libId);
    }

    @Override
    public boolean bindLockWithDoorcontact(int id, int dcId) {
        Future<VoidResult> future = mSmartclient.asyncLockBindDoorcontact(id, dcId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean asyncBindInfraredSocket(int id, int socketId) {
        Future<VoidResult> future = mSmartclient.asyncBindInfraredSocket(id, socketId);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean musicControllerPlayPause(int id) {
        Future<VoidResult> future = mSmartclient.asyncMusicControllerPlayPause(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean musicControllerPlayPre(int id) {
        Future<VoidResult> future = mSmartclient.asyncMusicControllerPlayPre(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean musicControllerPlayNext(int id) {
        Future<VoidResult> future = mSmartclient.asyncMusicControllerPlayNext(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean musicControllerPlayInMusicList(int id, int musicIndex) {
        Future<VoidResult> future = mSmartclient.asyncMusicControllerPlayInMusicList(id, musicIndex);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean musicControllerPlaySeek(int id, int seekTimeInMs) {
        Future<VoidResult> future = mSmartclient.asyncMusicControllerPlaySeek(id, seekTimeInMs);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setMusicControllerVolume(int id, int volume) {
        Future<VoidResult> future = mSmartclient.asyncSetMusicControllerVolume(id, volume);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setMusicControllerZoneVolume(int id, int zoneId, int zoneVolume, boolean volSwitch) {
        Future<VoidResult> future = mSmartclient.asyncSetMusicControllerZoneVolume(id, zoneId, zoneVolume, volSwitch);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean changeMusicControllerLoopMode(int id) {
        Future<VoidResult> future = mSmartclient.asyncChangeMusicControllerLoopMode(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean enbaleMusicControllerEQ(int id, boolean enable) {
        Future<VoidResult> future = mSmartclient.asyncEnbaleMusicControllerEQ(id, enable);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setMusicControllerEqMode(int id, String mode) {
        Future<VoidResult> future = mSmartclient.asyncSetMusicControllerEqMode(id, mode);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public List<GetYouzhuanMusicListResult.MusicListBean> queryYouzhuanMusicList(int id, String arg) {
        Future<GetYouzhuanMusicListResult> future = mSmartclient.asyncGetYouzhuanMusicList(id, arg);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get().getMusicList();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setYouzhuanMusicPlay(int id) {
        Future<VoidResult> future = mSmartclient.asyncSetYouzhuanMusicControllerPlay(id);
        return null;
    }

    @Override
    public VoidResult setYouzhuanMusicPause(int id) {
        Future<VoidResult> future = mSmartclient.asyncSetYouzhuanMusicControllerPause(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult playYouzhuanMusicPre(int id) {
        Future<VoidResult> future = mSmartclient.asyncPlayYouzhuanMusicControllerPre(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult playYouzhuanMusicNext(int id) {
        Future<VoidResult> future = mSmartclient.asyncPlayYouzhuanMusicControllerNext(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult playYouzhuanMusicByIndex(int id, int index) {
        Future<VoidResult> future = mSmartclient.asyncPlayYouzhuanMusicByIndex(id, index);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setYouzhuanMusicSeek(int id, int pos) {
        Future<VoidResult> future = mSmartclient.asyncSetYouzhuanMusicControllerPalyPos(id, pos);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setYouzhuanMusicVol(int id, int vol) {
        Future<VoidResult> future = mSmartclient.asyncSetYouzhuanMusicControllerVolume(id, vol);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setYouzhuanMusicLoopModel(int id, int model) {
        Future<VoidResult> future = mSmartclient.asyncSetYouzhuanMusicControllerLoopMode(id, model);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setYouzhuanMusicEq(int id, int eq) {
        Future<VoidResult> future = mSmartclient.asyncSetYouzhuanMusicControllerEq(id, eq);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setYouhzuanMusicSource(int id, int source) {
        Future<VoidResult> future = mSmartclient.asyncSetYouzhuanMusicControllerSource(id, source);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult startSearchYouzhuanMusic() {
        Future<VoidResult> future = mSmartclient.asyncStartSearchYouzhuanMusicController(0);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult stopSearchYouzhuanMusic() {
        Future<VoidResult> future = mSmartclient.asyncStopSearchYouzhuanMusicController(0);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Device editYouzhuanMusic(int id, String name, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncEditYouzhuanMusicControllerConfig(id, name, roomId);
        return editDeviceSync(id, future, SHDeviceType.NET_YouzhuanMusicController);
    }

    @Override
    public VoidResult delYouzhuanMusic(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelYouzhuanMusicControllerConfig(id);
        AsynTool.sync(future);
        try {
            if (future.isSuccess())
                return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean setHumidifierFogVol(int devId, int vol) {
        Future<VoidResult> future = mSmartclient.asyncKonkeHumidifierFogvolAdjust(devId, vol);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setHumidifierOnOff(int devId, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncKonkeHumidifierSwitch(devId, on);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setHumidifierConstantWet(int devId, boolean on, int vol) {
        Future<VoidResult> future = mSmartclient.asyncKonkeHumidifierConstandwet(devId, on, vol);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setAircleanrWindVol(int devId, int vol) {
        Future<VoidResult> future = mSmartclient.asyncKonkeAircleanerWindvolAdjust(devId, vol);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setAircleanrOnOff(int devId, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncKonkeAircleanerSwitch(devId, on);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setAircleanrAnionOnOff(int devId, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncKonkeAircleanerAnionSwitch(devId, on);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setAircleanrSleepOnOff(int devId, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncKonkeAircleanerModeSet(devId, on ? "SLEEP" : "NONE");
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public boolean setAircleanrAutoOnOff(int devId, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncKonkeAircleanerModeSet(devId, on ? "AUTO" : "NONE");
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public VoidResult fancoilSetSmartModel(int id, int modeId) {
        Future<VoidResult> future = mSmartclient.asyncFancoilSetSmartModel(id, modeId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult fancoilSetSmartModel(int id, FancoilSmartModel model) {
        Future<VoidResult> future = mSmartclient.asyncFancoilSetSmartModel(id, model);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult fancoilSetDelaytask(int id, boolean onEnable, String onDelayTime, boolean offEnable, String offDelayTime) {
        Future<VoidResult> future = mSmartclient.asyncFancoilSetDelaytask(id, onEnable, onDelayTime, offEnable, offDelayTime);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult fancoilSetRunTemp(int id, String temp) {
        Future<VoidResult> future = mSmartclient.asyncFancoilSetRunTemp(id, temp);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult fancoilSetFanSpeed(int id, ZigbeeFanCoilStatus.FANSPEED speed) {
        Future<VoidResult> future = mSmartclient.asyncFancoilSetFanSpeed(id, speed);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult fancoilSetRunModel(int id, ZigbeeFanCoilStatus.RUNMODEL model) {
        Future<VoidResult> future = mSmartclient.asyncFancoilSetRunModel(id, model);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetFancoilSmartModelResult fancoilGetSmartModel(int id) {
        Future<GetFancoilSmartModelResult> future = mSmartclient.asyncFancoilGetSmartModel(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    public boolean saveFancoilCustomSmartModel(int id, FancoilSmartModel model) {
        JsonObject argValue = JsonUtils.fromJson(JsonUtils.toJson(model), JsonObject.class);
        Future<VoidResult> future = mSmartclient.asyncSetDevAppArgWithType(id, SHDeviceType.ZIGBEE_FanCoil, "customSmartModel", argValue);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Override
    public FancoilSmartModel getFancoilCustomSmartModel(int id) {
        Future<GetDevAppArgsResult> future = mSmartclient.asyncGetDevAppArgs(id, SHDeviceType.ZIGBEE_FanCoil);
        AsynTool.sync(future);
        try {
            if (future.isSuccess()) {
                JsonArray array = future.get().getArgs();

                if (array != null) {
                    for (int i = 0; i < array.size(); i++) {
                        JsonObject obj = array.get(i).getAsJsonObject();
                        if (obj.get("arg_type").getAsString().equals("customSmartModel") && obj.get("arg").isJsonObject()) {
                            return JsonUtils.fromJson(obj.get("arg"), FancoilSmartModel.class);
                        }
                    }
                }
            }
        } catch (Exception e) {

        }
        return null;
    }

    @Override
    public GetFancoilSystemStatusResult fancoilGetSystemStatus(int id) {
        Future<GetFancoilSystemStatusResult> future = mSmartclient.asyncFancoilGetSystemStatus(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult fancoilSetLocking(int id, String locking) {
        Future<VoidResult> future = mSmartclient.asyncFancoilSetLocking(id, locking);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult fancoilSetLockStatus(int id, boolean lock) {
        Future<VoidResult> future = mSmartclient.asyncFancoilSetLockStatu(id, lock);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public FancoilConfigArgsResult getFancoilConfigArgs(int id) {
        Future<FancoilConfigArgsResult> future = mSmartclient.asyncGetFancoilConfigArgs(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetElectricalEnergyValueResult getElectricalEnergyValues(int id) {
        Future<GetElectricalEnergyValueResult> future = mSmartclient.asyncGetElectricalEnergyValue(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetElectricalEnergyArgsResult getElectricalEnergyArgs(int id) {
        Future<GetElectricalEnergyArgsResult> future = mSmartclient.asyncGetElectricalEnergyArgs(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetElectricalClearingInfoResult getElectricalClearningInfoResult(int id) {
        Future<GetElectricalClearingInfoResult> future = mSmartclient.asyncGetElectricalClearingInfo(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetElectricalClearingDateResult getElectricalClearningDateResult(int id) {
        Future<GetElectricalClearingDateResult> future = mSmartclient.asyncGetElectricalClearingDate(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetElectricalSwitchStatusResult getElectricalSwitchStatus(int id) {
        Future<GetElectricalSwitchStatusResult> future = mSmartclient.asyncGetElectricalSwitchStatus(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setElectricalSwitch(int id, boolean on) {
        Future<VoidResult> future = mSmartclient.asyncSetElectricalSwitch(id, on);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult editCodedLockUser(int id, int userId, int openType, boolean hijack, boolean permission, String key, int openTimes, String startTime, String endTime) {
        Future<VoidResult> future = mSmartclient.asyncEditCodedLockUser(id, userId, openType, hijack, permission, key, openTimes, startTime, endTime);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetCodedLockUserInfoResult getCodedLockUser(int id, int userId) {
        Future<GetCodedLockUserInfoResult> future = mSmartclient.asyncGetCodedLockUser(id, userId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public AddCodedLockUserResult addCodedLockUser(int id, int openType, boolean permission, boolean hijack, String key) {
        Future<AddCodedLockUserResult> future = mSmartclient.asyncAddCodedLockUser(id, openType, permission, hijack, key);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult delCodedLockUser(int id, int[] userId) {
        Future<VoidResult> future = mSmartclient.asyncDelCodedLockUser(id, userId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult delCodedLockAllUser(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelCodedLockAllUser(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult codedlockEnterCardmode(int id, boolean encrypt) {
        Future<VoidResult> future = mSmartclient.asyncCodedlockEnterCardmode(id, encrypt);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult clearAirSwitchAlarm(int id) {
        Future<VoidResult> future = mSmartclient.asyncClearAirSwitchAlarm(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetAirSwitchStatusResult getAirSwitchStatus(int id) {
        Future<GetAirSwitchStatusResult> future = mSmartclient.asyncGetAirSwitchStatus(id);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean delAirSwitch(int id) {
        Future<VoidResult> future = mSmartclient.asyncDelAirSwitch(id);
        AsynTool.sync(future);
        return future.isSuccess();
    }

    @Nullable
    private Device editDeviceSync(int devId, Future<VoidResult> future, SHDeviceType type) {
        AsynTool.sync(future);
        if (future.isSuccess()) {
            XLog.i("edit device success");
            Device device = mDevicerepository.findDevice(devId, type);
            return device;
        }
        XLog.f("edit device fail");
        return null;
    }

    @Override
    public void destroy() {
        mSmartclient.destory();
    }

    @Override
    public String getZigbeeDevHwVersion(String mac) {
        return mDevicerepository.findZigbeeDeviceHwVersion(mac);
    }

    @Override
    public void resetTimeInterval() {
        mSmartclient.resetTimeInterval();
    }

    @Override
    public void reconect(int delay) {
        mSmartclient.reConnet(delay);
    }

    @Override
    public GetZbDevOnlineSwitchResult getZbDevSwitchStatus(int gwId) {
        Future<GetZbDevOnlineSwitchResult> future = mSmartclient.asyncGetZbDevOnlineSwitch(gwId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult setZbDevSwitchStatus(int gwId, String arg) {
        Future<VoidResult> future = mSmartclient.asyncSetZbDevOnlineSwitch(gwId, arg);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult delFloorheatingDev(int deviceId) {
        Future<VoidResult> future = mSmartclient.asyncDelFlootHeatingDev(deviceId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult addAirBox(String mac, String type) {
        Future<VoidResult> future = mSmartclient.asyncAddAirBoxDevice(mac, type);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public VoidResult delAirBoxDev(int deviceId) {
        Future<VoidResult> future = mSmartclient.asyncDelAirBoxDevice(deviceId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Device setAirBox(int devId, String name, int roomId) {
        Future<VoidResult> future = mSmartclient.asyncSetAirBoxDevice(devId, roomId, name);
        return editDeviceSync(devId, future, SHDeviceType.NET_AIR_BOX);
    }

    @Override
    public GetAirBoxStateResult getAirBoxStete(int devId, int arg) {
        Future<GetAirBoxStateResult> future = mSmartclient.asyncGetAirBoxState(devId, arg);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public GetAirBoxDayStatisitcResult getAirBoxDayStatisitc(int devId, String field, String start, String end) {
        Future<GetAirBoxDayStatisitcResult> future = mSmartclient.asyncGetAirBoxDatStatis(devId, field, start, end);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public AirBoxNodeArgResult getAirboxNodeArg(int devId) {
        Future<AirBoxNodeArgResult> future = mSmartclient.asyncGetAirBoxNodeArg(devId);
        AsynTool.sync(future);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }

}
